package top.hidoctor.auscultation.feature.activity;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;
import com.google.gson.Gson;
import com.tang.net.NetClient;
import com.tang.user.UserInfo;
import com.tang.user.UserInfoManager;
import com.tang.util.AppUtil;
import com.tang.util.TimeUtil;
import com.tbruyelle.rxpermissions2.RxPermissions;
import com.zhihu.matisse.Matisse;
import com.zhihu.matisse.MimeType;
import com.zhihu.matisse.filter.Filter;
import com.zhihu.matisse.internal.entity.CaptureStrategy;
import com.zhihu.matisse.internal.entity.IncapableCause;
import com.zhihu.matisse.internal.entity.Item;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONArray;

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import io.reactivex.functions.Consumer;
import top.hidoctor.auscultation.App;
import top.hidoctor.auscultation.R;
import top.hidoctor.auscultation.base.BaseActivity;
import top.hidoctor.auscultation.base.Constant;
import top.hidoctor.auscultation.bean.DictionaryBean;
import top.hidoctor.auscultation.bean.Hospitalbean;
import top.hidoctor.auscultation.bean.JsonBean;
import top.hidoctor.auscultation.bean.User;
import top.hidoctor.auscultation.event.UserEvent;
import top.hidoctor.auscultation.net.c.SettingContract;
import top.hidoctor.auscultation.net.p.SettingPresenter;
import top.hidoctor.auscultation.net.req.DictionaryReq;
import top.hidoctor.auscultation.net.req.UsersReq;
import top.hidoctor.auscultation.utils.GetJsonDataUtil;
import top.hidoctor.auscultation.utils.GlideLoadEngine;
import top.hidoctor.auscultation.utils.IdentityUtils;
import top.hidoctor.auscultation.widget.GlideCircleTransform;
import top.hidoctor.auscultation.widget.roundimageview.RoundedImageView;

public class SettingActivity extends BaseActivity implements SettingContract.View, View.OnClickListener {


    private Toolbar toolbar;
    private TextView tvTitle, tvGender, tvNation, tvZhuangye, tvJuese, tvZhicheng, tvXueli, tvAddress, tvXuewei, tvHos;
    private RelativeLayout rlAvatar;
    private RoundedImageView ivAvater;
    private EditText editName, editPhone, editIdcard, editBrithday, editEmail, editAddressDetail;
    private SettingPresenter presenter;
    private Button btnAdd;
    private DictionaryReq req;
    private List<DictionaryBean.ResultBean> specialtyList = new ArrayList<>(); //专业
    private List<DictionaryBean.ResultBean> positionList = new ArrayList<>();//职称
    private List<DictionaryBean.ResultBean> educationList = new ArrayList<>();// 学历
    private List<DictionaryBean.ResultBean> degreeList = new ArrayList<>();// 学位
    private RxPermissions rxPermissions;
    private final int REQUEST_CODE_CHOOSE_PHOTO_ALBUM = 1;

    private ArrayList<JsonBean> options1Items = new ArrayList<>();
    private ArrayList<ArrayList<JsonBean.CitiesBean>> options2Items = new ArrayList<>();
    private ArrayList<ArrayList<ArrayList<JsonBean.CitiesBean.CountiesBean>>> options3Items = new ArrayList<>();
    private Thread thread;
    private static final int MSG_LOAD_DATA = 0x0001;
    private static final int MSG_LOAD_SUCCESS = 0x0002;
    private static final int MSG_LOAD_FAILED = 0x0003;
    private String province;
    private String city;
    private String provinceId;
    private String cityId;
    private String area;
    private String areaId;
    private boolean isLoaded = false;
    /**
     * 权限组
     */
    private static final String[] permissionsGroup = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA};
    private String file = "";
    private UsersReq usersReq;
    private User user;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        presenter = new SettingPresenter(this, this);
        req = new DictionaryReq();
        usersReq = new UsersReq();

        initView();
        initEvent();
    }

    private void initView() {
        toolbar = findViewById(R.id.toolbar);
        tvTitle = findViewById(R.id.tv_title);
        toolbar.setNavigationIcon(R.mipmap.ic_back_left);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        tvTitle.setText("个人编辑");

        btnAdd = findViewById(R.id.btn_add);
        rlAvatar = findViewById(R.id.rl_avatar);
        ivAvater = findViewById(R.id.iv_avater);
        editName = findViewById(R.id.edit_name);
        tvGender = findViewById(R.id.tv_gender);
        editPhone = findViewById(R.id.edit_phone);
        editIdcard = findViewById(R.id.edit_idcard);
        editBrithday = findViewById(R.id.edit_brithday);
        tvNation = findViewById(R.id.tv_nation);
        tvZhuangye = findViewById(R.id.tv_zhuangye);
        tvJuese = findViewById(R.id.tv_juese);
        tvHos = findViewById(R.id.tv_hos);
        tvZhicheng = findViewById(R.id.tv_zhicheng);
        tvXueli = findViewById(R.id.tv_xueli);
        tvXuewei = findViewById(R.id.tv_xuewei);
        editEmail = findViewById(R.id.edit_email);
        tvAddress = findViewById(R.id.tv_address);
        editAddressDetail = findViewById(R.id.edit_address_detail);

        rlAvatar.setOnClickListener(this);
        tvGender.setOnClickListener(this);
        tvNation.setOnClickListener(this);
        tvJuese.setOnClickListener(this);
        tvZhuangye.setOnClickListener(this);
        tvHos.setOnClickListener(this);
        tvZhicheng.setOnClickListener(this);
        tvXuewei.setOnClickListener(this);
        tvXueli.setOnClickListener(this);
        tvAddress.setOnClickListener(this);
        btnAdd.setOnClickListener(this);

        req.setGroupCode("EMPLOYEE_SPECIALTY");
        presenter.getDictionary(req);
        req.setGroupCode("EMPLOYEE_POSITION");
        presenter.getDictionary(req);
        req.setGroupCode("EMPLOYEE_EDUCATION");
        presenter.getDictionary(req);
        req.setGroupCode("EMPLOYEE_DEGREE");
        presenter.getDictionary(req);

        rxPermissions = new RxPermissions(this);


        editIdcard.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence pCharSequence, int pI, int pI1, int pI2) {

            }

            @Override
            public void onTextChanged(CharSequence pCharSequence, int pI, int pI1, int pI2) {
                // 键盘输入时的监听
                if (IdentityUtils.checkIDCard(pCharSequence.toString())) {
                    editBrithday.setText(AppUtil.getBirthday(pCharSequence.toString()));
                } else {
                    editBrithday.setText("无法识别");
                }

            }

            @Override
            public void afterTextChanged(Editable pEditable) {

            }
        });

    }

    private void initEvent() {
        presenter.getUser(UserInfoManager.getInstance().getUserInfo().getUserId());
        new Thread(new Runnable() {
            @Override
            public void run() {
                mHandler.sendEmptyMessage(MSG_LOAD_DATA);
            }
        }).start();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_avatar:
                if (!AppUtil.isFastClick()) {
                    rxPermissions.request(permissionsGroup)
                            .subscribe(new Consumer<Boolean>() {
                                @Override
                                public void accept(Boolean aBoolean) throws Exception {
                                    if (aBoolean) {
                                        //申请的权限全部允许
                                        imagePick();
                                    } else {
                                        //只要有一个权限被拒绝，就会执行
                                        showToast("权限被禁止，无法打开相机、相册");
                                    }

                                }
                            });
                }
                break;
            case R.id.tv_gender:
                if (!AppUtil.isFastClick()) {
                    hideSoft(tvGender);
                    showPicker(1);
                }
                break;
            case R.id.tv_nation:
                if (!AppUtil.isFastClick()) {
                    hideSoft(tvNation);
                    showPicker(2);
                }
                break;
            case R.id.tv_zhuangye:
                if (!AppUtil.isFastClick()) {
                    hideSoft(tvZhuangye);
                    showPicker(3);
                }
                break;
            case R.id.tv_zhicheng:
                if (!AppUtil.isFastClick()) {
                    hideSoft(tvZhicheng);
                    showPicker(4);
                }
                break;

            case R.id.tv_xuewei:
                if (!AppUtil.isFastClick()) {
                    hideSoft(tvXuewei);
                    showPicker(5);
                }
                break;
            case R.id.tv_xueli:
                if (!AppUtil.isFastClick()) {
                    hideSoft(tvXueli);
                    showPicker(6);
                }
                break;
            case R.id.tv_address:
                hideSoft(tvAddress);
                if (isLoaded) {
                    showPickerView();
                } else {
                    Toast.makeText(SettingActivity.this, "Please waiting until the data is parsed", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.btn_add:
                String name = editName.getText().toString();
                String phone = editPhone.getText().toString();
                String idcard = editIdcard.getText().toString();
                String zhuanye = tvZhuangye.getText().toString();
                String zhicheng = tvZhicheng.getText().toString();
                String xueli = tvXueli.getText().toString();
                if (TextUtils.isEmpty(name)) {
                    showToast("请输入姓名");
                    return;
                }
                if (TextUtils.isEmpty(phone)) {
                    showToast("请输入手机号");
                    return;
                }
                if (TextUtils.isEmpty(idcard)) {
                    showToast("请输入身份证号码");
                    return;
                }
                if (!IdentityUtils.checkIDCard(idcard)) {
                    showToast("请输入正确的身份证号码");
                    return;
                }
                if (TextUtils.isEmpty(zhuanye)) {
                    showToast("请选择专业");
                    return;
                }
                if (TextUtils.isEmpty(zhicheng)) {
                    showToast("请选择职称");
                    return;
                }
                if (TextUtils.isEmpty(xueli)) {
                    showToast("请选择学历");
                    return;
                }
                usersReq.setAddress(tvAddress.getText().toString());
                usersReq.setAvatar(TextUtils.isEmpty(file) ? user.getAvatar() : file);
                usersReq.setRealName(name);
                usersReq.setGender(tvGender.getText().toString().equals("男") ? 1 : tvGender.getText().toString().equals("女") ? 2 : 0);
                usersReq.setIdCard(idcard);
                usersReq.setBirthday(editBrithday.getText().toString() + " 00:00:00");
                usersReq.setDetailAddress(editAddressDetail.getText().toString());
                usersReq.setEmail(editEmail.getText().toString());
                usersReq.setHospital(new UsersReq.HospitalBean(user.getHospital().getHospitalName(), user.getHospital().getId()));
                usersReq.setRole(new UsersReq.RoleBean(user.getRole().getId(), user.getRole().getName()));
                usersReq.setPhone(phone);
                presenter.updateInfo(user.getId(), usersReq);

                break;
        }
    }

    /**
     *
     * @param type
     */
    private void showPicker(final int type) {
        final List<String> list = new ArrayList<>();
        if (type == 1) {//性别
            list.add("男");
            list.add("女");
        } else if (type == 2) {//民族
            list.addAll(Arrays.asList(Constant.nation));
        } else if (type == 3) {//专业
            for (int i = 0; i < specialtyList.size(); i++) {
                list.add(specialtyList.get(i).getTitle());
            }
        } else if (type == 4) {//职称
            for (int i = 0; i < positionList.size(); i++) {
                list.add(positionList.get(i).getTitle());
            }
        } else if (type == 5) {//学位
            for (int i = 0; i < educationList.size(); i++) {
                list.add(educationList.get(i).getTitle());
            }
        } else if (type == 6) {//学历
            for (int i = 0; i < degreeList.size(); i++) {
                list.add(degreeList.get(i).getTitle());
            }
        }
        OptionsPickerView optionsPicker = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                if (type == 1) {
                    tvGender.setText(list.get(options1));
                } else if (type == 2) {
                    tvNation.setText(list.get(options1));
                    usersReq.setNation(list.get(options1));
                } else if (type == 3) {
                    tvZhuangye.setText(list.get(options1));
                    usersReq.setSpecialty(specialtyList.get(options1).getId());
                } else if (type == 4) {
                    tvZhicheng.setText(list.get(options1));
                    usersReq.setPosition(positionList.get(options1).getId());
                } else if (type == 5) {
                    tvXuewei.setText(list.get(options1));
                    usersReq.setEducation(educationList.get(options1).getId());
                } else if (type == 6) {
                    tvXueli.setText(list.get(options1));
                    usersReq.setDegree(degreeList.get(options1).getId());
                }
            }
        })
                .setTitleText(type == 1 ? "选择性别" : type == 2 ? "选择民族" : type == 3 ? "选择专业" : type == 4 ? "选择职称" : type == 5 ? "选择学位" : type == 6 ? "选择学历" : "")
                .setDividerColor(ContextCompat.getColor(this, R.color.blue_main))
                .setTitleSize(18)
                .setContentTextSize(15)
                .setOutSideCancelable(true)
                .setSubmitColor(ContextCompat.getColor(this, R.color.blue_main))
                .setCancelColor(ContextCompat.getColor(this, R.color.colorHintText))
                .setTextColorCenter(ContextCompat.getColor(this, R.color.blue_main)) //设置选中项文字颜色
                .build();
        optionsPicker.setPicker(list);
        optionsPicker.show();
    }

    /**
     * 选择图片
     */
    private void imagePick() {
        Matisse.from(this)
                .choose(MimeType.ofImage(), false)
                .capture(true)
                .captureStrategy(new CaptureStrategy(true, "top.hidoctor.auscultation"))
                .theme(R.style.Matisse_Dracula)
                .countable(true)
                .maxSelectable(1)
                .addFilter(new Filter() {
                    @Override
                    protected Set<MimeType> constraintTypes() {
                        return new HashSet<MimeType>() {{
                            add(MimeType.PNG);
                        }};
                    }

                    @Override
                    public IncapableCause filter(Context context, Item item) {
                        try {
                            InputStream inputStream = getContentResolver().openInputStream(item.getContentUri());
                            BitmapFactory.Options options = new BitmapFactory.Options();
                            options.inJustDecodeBounds = true;
                            BitmapFactory.decodeStream(inputStream, null, options);
                            int width = options.outWidth;
                            int height = options.outHeight;

//                            if (width >= 500)
//                                return new IncapableCause("宽度超过500px");

                        } catch (FileNotFoundException e) {
                            e.printStackTrace();
                        }
                        return null;
                    }
                })
                .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
                .thumbnailScale(0.87f)
                .imageEngine(new GlideLoadEngine())
                .forResult(REQUEST_CODE_CHOOSE_PHOTO_ALBUM);

    }

    /**
     *
     * @param user
     */
    @Override
    public void getUserSuc(User user) {
        if (user != null) {
            this.user = user;

            RequestOptions optionsCircle = new RequestOptions();
            DrawableTransitionOptions transitionOptions = new DrawableTransitionOptions();
            Glide.with(mContext)
                    .load(NetClient.IMG_URL + user.getAvatar())
                    .apply(optionsCircle.transform(new GlideCircleTransform()).placeholder(R.drawable.ic_avater_zw))
                    .transition(transitionOptions.crossFade())
                    .into(ivAvater);
            editName.setText(user.getRealName());
            tvGender.setText(user.getGender() == 1 ? "男" : user.getGender() == 2 ? "女" : "保密");
            editPhone.setText(user.getPhone());
            editBrithday.setText(user.getBirthday() != null ? TimeUtil.formatTime(user.getBirthday(), TimeUtil.Y_M_D) : "");
            editIdcard.setText(user.getIdcard());
            tvNation.setText(user.getNation());
            tvZhuangye.setText(user.getSpecialtyName());
            tvJuese.setText(user.getRole().getName());
            tvHos.setText(user.getHospital().getHospitalName());
            tvZhicheng.setText(user.getPositionName());
            tvXueli.setText(user.getEducationName());
            tvXuewei.setText(user.getDegreeName());
            editEmail.setText(user.getEmail());
            tvAddress.setText(user.getAddress());
            editAddressDetail.setText(user.getDetailAddress());

            UserInfoManager.getInstance().getUserInfo().setAvatar(user.getAvatar());
            UserInfoManager.getInstance().getUserInfo().setRealName(user.getRealName());
            EventBus.getDefault().post(new UserEvent());
        }
    }

    /**
     *
     * @param bean
     */
    @Override
    public void getDictionarySuc(DictionaryBean bean) {
        String groupCode = "";
        if (bean.getResult().size() > 0) {
            groupCode = bean.getResult().get(0).getGroupCode();
        }
        if (groupCode.equals("EMPLOYEE_SPECIALTY")) {
            specialtyList.addAll(bean.getResult());
        } else if (groupCode.equals("EMPLOYEE_POSITION")) {
            positionList.addAll(bean.getResult());
        } else if (groupCode.equals("EMPLOYEE_EDUCATION")) {
            educationList.addAll(bean.getResult());
        } else if (groupCode.equals("EMPLOYEE_DEGREE")) {
            degreeList.addAll(bean.getResult());
        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE_CHOOSE_PHOTO_ALBUM && resultCode == RESULT_OK) {
            //图片路径 同样视频地址也是这个 根据requestCode
            List<String> pathList = Matisse.obtainPathResult(data);
            if (pathList.size() > 0) {
                RequestOptions optionsCircle = new RequestOptions();
                DrawableTransitionOptions transitionOptions = new DrawableTransitionOptions();
                Glide.with(mContext)
                        .load(pathList.get(0))
                        .apply(optionsCircle.transform(new GlideCircleTransform()).placeholder(R.drawable.ic_avater_zw))
                        .transition(transitionOptions.crossFade())
                        .into(ivAvater);
                presenter.uploadFile(pathList.get(0), REQUEST_CODE_CHOOSE_PHOTO_ALBUM);
            }
        }
    }


    /**
     *
     * @param data
     * @param type
     */
    @Override
    public void getFileScu(String data, int type) {
        this.file = data;
    }

    /**
     *
     */
    @Override
    public void updateInfoSuc() {
        showToast("用戶信息更新完成");
        presenter.getUser(UserInfoManager.getInstance().getUserInfo().getUserId());
    }

    @Override
    public void getHospitalListSuc(Hospitalbean hospitalbean) {

    }

    /**
     *
     */
    private void showPickerView() {// 弹出选择器

        OptionsPickerView pvOptions = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                //返回的分别是三个级别的选中位置
                if (options3Items.get(options1).get(options2).get(options3) != null) {
                    tvAddress.setText(options1Items.get(options1).getPickerViewText() + ","
                            + options2Items.get(options1).get(options2).getAreaName() + ","
                            + options3Items.get(options1).get(options2).get(options3).getAreaName());
                    provinceId = options1Items.get(options1).getAreaId();
                    cityId = options2Items.get(options1).get(options2).getAreaId();
                    areaId = options3Items.get(options1).get(options2).get(options3).getAreaId();

                } else {
                    tvAddress.setText(options1Items.get(options1).getPickerViewText() + ","
                            + options2Items.get(options1).get(options2).getAreaName());

                    provinceId = options1Items.get(options1).getAreaId();
                    cityId = options2Items.get(options1).get(options2).getAreaId();
                }
            }
        })

                .setTitleText("城市选择")
                .setDividerColor(Color.BLACK)
                .setTitleSize(18)
                .setContentTextSize(15)
                .setSubmitColor(ContextCompat.getColor(SettingActivity.this, R.color.blue_main))
                .setCancelColor(ContextCompat.getColor(SettingActivity.this, R.color.colorHintText))
                .setTextColorCenter(ContextCompat.getColor(SettingActivity.this, R.color.blue_main)) //设置选中项文字颜色
                .build();

        /*pvOptions.setPicker(options1Items);//一级选择器
        pvOptions.setPicker(options1Items, options2Items);//二级选择器*/
        pvOptions.setPicker(options1Items, options2Items, options3Items);//三级选择器
        pvOptions.show();
    }


    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MSG_LOAD_DATA:
                    if (thread == null) {//如果已创建就不再重新创建子线程了
//                        Toast.makeText(EditAddressActivity.this, "Begin Parse Data", Toast.LENGTH_SHORT).show();
                        thread = new Thread(new Runnable() {
                            @Override
                            public void run() {
                                // 子线程中解析省市区数据
                                initJsonData();
                            }
                        });
                        thread.start();
                    }
                    break;

                case MSG_LOAD_SUCCESS:
                    isLoaded = true;
                    break;

                case MSG_LOAD_FAILED:
                    Toast.makeText(SettingActivity.this, "Parse Failed", Toast.LENGTH_SHORT).show();
                    break;
            }
        }
    };

    /**
     *
     */
    private void initJsonData() {//解析数据
        /**
         * 注意：assets 目录下的Json文件仅供参考，实际使用可自行替换文件
         * 关键逻辑在于循环体
         *
         * */
        String JsonData = new GetJsonDataUtil().getJson(this, "city.json");//获取assets目录下的json文件数据

        ArrayList<JsonBean> jsonBean = parseData(JsonData);//用Gson 转成实体

        /**
         * 添加省份数据
         *
         * 注意：如果是添加的JavaBean实体，则实体类需要实现 IPickerViewData 接口，
         * PickerView会通过getPickerViewText方法获取字符串显示出来。
         */
        options1Items = jsonBean;

        for (int i = 0; i < jsonBean.size(); i++) {//遍历省份
            ArrayList<JsonBean.CitiesBean> CityList = new ArrayList<>();//该省的城市列表（第二级）
            ArrayList<ArrayList<JsonBean.CitiesBean.CountiesBean>> Province_AreaList = new ArrayList<>();//该省的所有地区列表（第三极）

            for (int c = 0; c < jsonBean.get(i).getCities().size(); c++) {//遍历该省份的所有城市
                JsonBean.CitiesBean citiesBean = jsonBean.get(i).getCities().get(c);
                CityList.add(citiesBean);//添加城市
                ArrayList<JsonBean.CitiesBean.CountiesBean> City_AreaList = new ArrayList<>();//该城市的所有地区列表

                //如果无地区数据，建议添加空字符串，防止数据为null 导致三个选项长度不匹配造成崩溃
                if (jsonBean.get(i).getCities().get(c).getAreaName() == null
                        || jsonBean.get(i).getCities().get(c).getCounties().size() == 0) {
                    City_AreaList.add(null);
                } else {
                    City_AreaList.addAll(jsonBean.get(i).getCities().get(c).getCounties());
                }
                Province_AreaList.add(City_AreaList);//添加该省所有地区数据
            }

            /**
             * 添加城市数据
             */
            options2Items.add(CityList);

            /**
             * 添加地区数据
             */
            options3Items.add(Province_AreaList);
        }
        mHandler.sendEmptyMessage(MSG_LOAD_SUCCESS);

    }


    public ArrayList<JsonBean> parseData(String result) {//Gson 解析
        ArrayList<JsonBean> detail = new ArrayList<>();
        try {
            JSONArray data = new JSONArray(result);
            Gson gson = new Gson();
            for (int i = 0; i < data.length(); i++) {
                JsonBean entity = gson.fromJson(data.optJSONObject(i).toString(), JsonBean.class);
                detail.add(entity);
            }
        } catch (Exception e) {
            e.printStackTrace();
            mHandler.sendEmptyMessage(MSG_LOAD_FAILED);
        }
        return detail;
    }


}
